<?php
session_start();
 if (empty($_SESSION['username']) AND empty($_SESSION['passuser'])){
  echo "<link href='style.css' rel='stylesheet' type='text/css'>
 <center>Untuk mengakses modul, Anda harus login <br>";
  echo "<a href=../../index.php><b>LOGIN</b></a></center>";
}
else{
$aksi="modul/mod_pesan/aksi_pesan.php";
$upass = $_SESSION['passuser'];
$gu = mysql_query("SELECT username FROM users WHERE password='$upass'");
$uname = mysql_fetch_object($gu);
$usrnm = $uname->username;
switch($_GET[act]){
  // Daftar Pesan
  default:
    echo "<div class='componentheading'>Daftar Pesan</div>
          <input type=button value='Input Pesan' 
          onclick=\"window.location.href='?module=pesan&act=tambahpesan';\">
		  <p>
          <table class='boslist'>
          <tr><th>No</th><th width='70%'>Isi Pesan</th><th>Username</th><th>Aksi</th></tr>"; 
    $tampil=mysql_query("SELECT * FROM pesan ORDER BY id_pesan DESC");
    $no=1;
    while ($r=mysql_fetch_array($tampil)){
       echo "<tr><td align='right'>$no</td>
             <td>$r[pesan]</td>
             <td align='center'>$r[username]</td>
             <td align='center'><a href=?module=pesan&act=editpesan&id=$r[id_pesan]>Edit</a> | 
	               <a href=$aksi?module=pesan&act=hapus&id=$r[id_pesan]>Hapus</a> |
				   <a href='?module=sms&act=kirimpesan&id=$r[id_pesan]'>Kirim</a>
             </td></tr>";
      $no++;
    }
    echo "</table></p>";
    break;
  
  // Form Input Pesan
  case "tambahpesan":
    echo "<div class='componentheading'>Form Input Pesan</div>
          <form method=POST action='$aksi?module=pesan&act=input'>
		  <p>
			<strong>Isi Pesan :</strong><br />
			<textarea name='pesan' class='teks' style='width:600px; height:200px;'></textarea>
		  </p>
		  <input type='hidden' name='user' value='".$usrnm."' />
		  <p>
			<input type='submit' name='submit' value='Simpan' />&nbsp;
            <input type='button' value='Batal' onclick='self.history.back()' />
		  </p>
          </form>";
     break;
  
  // Form Edit Pesan 
  case "editpesan":
    $edit=mysql_query("SELECT * FROM pesan WHERE id_pesan='$_GET[id]'");
    $r=mysql_fetch_array($edit);

    echo "<div class='componentheading'>Edit Pesan</div>
          <form method=POST action=$aksi?module=pesan&act=update>
          <input type=hidden name=id value='$r[id_pesan]'>
		  <p>
			<strong>Isi Pesan :</strong><br />
			<textarea name='pesan' class='teks' style='width:600px; height:200px;'>$r[pesan]</textarea>
		  </p>
		  <input type='hidden' name='user' value='".$usrnm."' />
		  <p>
			<input type='submit' name='submit' value='Simpan' />&nbsp;
            <input type='button' value='Batal' onclick='self.history.back()' />
		  </p></form>";
    break;  
}
}
?>
